package zcw.com.lib_leet_code;

/**
 * Created by 朱城委 on 2021/7/15.<br><br>
 *
 * 最大连续 1 的个数
 */
public class Topic485 {

    public static void main(String[] args) {
        Topic485 instance = new Topic485();

        int[] array = new int[] {1,1,0,1,1,1};
        System.out.println(instance.findMaxConsecutiveOnes(array));

        array = new int[] {1,0,1,1,0,1};
        System.out.println(instance.findMaxConsecutiveOnes(array));
    }

    public int findMaxConsecutiveOnes(int[] nums) {
        int max = 0;
        int counter = 0;
        for(int value : nums) {
            if(value == 1) {
                counter++;
            }
            else {
                if(counter > max) {
                    max = counter;
                }

                counter = 0;
            }
        }

        if(counter > max) {
            max = counter;
        }

        return max;
    }
}
